package djboom.materials.display.elements {
	import djboom.materials.core.DataCore;

	import flash.events.Event;
	import flash.text.AntiAliasType;
	import flash.text.TextFieldAutoSize;
	import flash.display.BitmapData;

	import org.casalib.display.CasaTextField;
	import org.casalib.display.CasaBitmap;

	import flash.text.TextFormat;

	import djboom.materials.state.Font;

	import org.casalib.display.CasaSprite;

	/**
	 * .
	 * <br>
	 * 
	 * @author DJ BooM 
	 * @since 20.05.2010
	 * 
	 */

	public class SampleDragged extends CasaSprite {

		// ----------------------------------------------------------------------------
		// Константы класса.
		// ----------------------------------------------------------------------------

		private static const TITLE_TFORMAT:TextFormat = new TextFormat(Font.MYRIAD_PRO_COND, 22, 0x004064, null, true, null, null, null, "center");		private static const HARDNESS_TFORMAT:TextFormat = new TextFormat(Font.MYRIAD_PRO_COND, 18, 0x004064, true, true, null, null, null, "center");

		// ----------------------------------------------------------------------------
		// Свойства класса.
		// ----------------------------------------------------------------------------

		private var _bitmapSample:CasaBitmap;
		private var _rhombusShape:Rhombus;
		private var _hardnessField:CasaTextField;
		private var _titleField:CasaTextField;

		private var _initX:int = 0;

		private var _hardness:String;

		
		
		// ----------------------------------------------------------------------------
		// Конструктор.
		// ----------------------------------------------------------------------------

		public function SampleDragged(sampleName:String, bitmapData:BitmapData, sampleHardness:String) {
			super();
			
			_hardness = sampleHardness;
				
			this.buttonMode = true;         
			this.useHandCursor = true;
            
			_bitmapSample = new CasaBitmap(bitmapData);
			_bitmapSample.x = 40;
			addChild(_bitmapSample);
            
			_rhombusShape = new Rhombus(Rhombus.BLUE);
			_rhombusShape.x = 40;
			addChild(_rhombusShape);
            
			_titleField = new CasaTextField();
			_titleField.embedFonts = true;
			_titleField.selectable = false;
			_titleField.multiline = true;
			_titleField.wordWrap = true;
			_titleField.width = 200;
			_titleField.defaultTextFormat = TITLE_TFORMAT;
			_titleField.autoSize = TextFieldAutoSize.CENTER;
			_titleField.antiAliasType = AntiAliasType.ADVANCED;
			_titleField.text = sampleName;
			_titleField.mouseEnabled = false;
			_titleField.thickness = 50;
			_titleField.y = 115;
			addChild(_titleField);
            
			_hardnessField = new CasaTextField();
			_hardnessField.embedFonts = true;
			_hardnessField.selectable = false;
			_hardnessField.width = 210;
			_hardnessField.multiline = true;
			_hardnessField.wordWrap = true;
			_hardnessField.defaultTextFormat = HARDNESS_TFORMAT;
			_hardnessField.autoSize = TextFieldAutoSize.CENTER;
			_hardnessField.antiAliasType = AntiAliasType.ADVANCED;			_hardnessField.styleSheet = DataCore.STYLESHEET;
			_hardnessField.htmlText = sampleHardness + ' кг/м  <span class="specialSymbols">3</span>';
			_hardnessField.mouseEnabled = false;
			_hardnessField.thickness = 50;			
			_hardnessField.y = _titleField.y + _titleField.textHeight;
			addChild(_hardnessField);
            
			addEventListener(Event.REMOVED_FROM_STAGE, clearPage);
		}	 

		// ----------------------------------------------------------------------------
		// Методы класса.
		// ----------------------------------------------------------------------------

		private function clearPage(event:Event):void {
			_bitmapSample.destroy();
			_bitmapSample = null;
            
			_rhombusShape.destroy();
			_rhombusShape = null;
            
			_hardnessField.destroy();
			_hardnessField = null;
			
			_titleField.destroy();
			_titleField = null;
		}

		// ----------------------------------------------------------------------------
		// Публичные методы.
		// ----------------------------------------------------------------------------
			
		// ----------------------------------------------------------------------------
		// Публичные свойства.
		// ----------------------------------------------------------------------------

		public function get initX():int {
			return _initX;
		}

		public function set initX(initX:int):void {
			_initX = initX;
		}

		public function get hardness():String {
			return _hardness;
		}
	}
}
